package com.denlaku.longan.repository;

import com.denlaku.longan.dao.GoingInDao;
import com.denlaku.longan.vo.GoingIn;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;

/**
 * @author tianx
 */
@Repository
public class GoingInRepository {
    @Autowired
    private GoingInDao goingInDao;

    /**
     * 批量保存组件下钻信息
     *
     * @param goingInList 组件下钻信息
     */
    public void batchAdd(List<GoingIn> goingInList) {
        List<List<GoingIn>> partitions = ListUtils.partition(ListUtils.emptyIfNull(goingInList), 100);
        for (List<GoingIn> partition : partitions) {
            goingInDao.batchAdd(partition);
        }
    }

    /**
     * 删除组件下钻信息
     *
     * @param tenantId 租户id
     * @param componentIds 组件id
     */
    public void delete(Long tenantId, List<Long> componentIds) {
        if (CollectionUtils.isNotEmpty(componentIds)) {
            goingInDao.delete(tenantId, componentIds);
        }
    }

    /**
     * 查询组件下钻信息
     *
     * @param tenantId 租户ID
     * @param componentIds 组件ID
     * @return 组件下钻信息
     */
    public List<GoingIn> list(Long tenantId, List<Long> componentIds) {
        if (CollectionUtils.isEmpty(componentIds)) {
            return Collections.emptyList();
        }
        return goingInDao.list(tenantId, componentIds);
    }

}
